package com.oh.core.custom;

import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.nio.channels.SocketChannel;
import java.util.UUID;

/**
 * 重写NioSocketChannel
 */
public class OhNioSocketChannel extends NioSocketChannel {
    public OhNioSocketChannel(Channel parent, SocketChannel socket){
        super(parent, socket);
    }

    // 自定义ID
    @Override
    protected ChannelId newId() {
        return new ChannelId() {
            private final String id = UUID.randomUUID().toString().replaceAll("-","");

            @Override
            public String asShortText() {
                return id;
            }

            @Override
            public String asLongText() {
                return id;
            }

            @Override
            public int compareTo(ChannelId o) {
                return id.equals(o.asLongText()) ? 1 : 0;
            }
        };
    }

}
